package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.product.service.api.BaseTrademarkService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: 封捷
 * @create-date: 2022/8/22 9:28
 */
@Api(tags = "品牌信息接口")
@RestController
@RequestMapping("/admin/product")
public class BaseTrademarkController {

    @Autowired
    private BaseTrademarkService baseTrademarkService;

    // page 参数：页码
    // limit 参数：每页显示数据条数
    @GetMapping("/baseTrademark/{page}/{limit}")
    public Result<IPage<BaseTrademark>> getTMPage(
            @PathVariable("page") Long page,
            @PathVariable("limit") Long limit) {

        IPage<BaseTrademark> iPage = baseTrademarkService.page(new Page<BaseTrademark>(page, limit), null);

        return Result.ok(iPage);
    }

    @PostMapping("/baseTrademark/save")
    public Result<Void> saveBaseTrademark(@RequestBody BaseTrademark baseTrademark) {

        baseTrademarkService.save(baseTrademark);

        return Result.ok();
    }

    @PutMapping("/baseTrademark/update")
    public Result<Void> updateBaseTrademark(@RequestBody BaseTrademark baseTrademark) {

        baseTrademarkService.updateById(baseTrademark);

        return Result.ok();
    }

    @DeleteMapping("/baseTrademark/remove/{id}")
    public Result<Void> removeBaseTrademark(@PathVariable("id") Long id) {

        baseTrademarkService.removeById(id);

        return Result.ok();
    }

    @GetMapping("/baseTrademark/get/{id}")
    public Result<BaseTrademark> getTrademarkById(@PathVariable Long id) {
        return Result.ok(baseTrademarkService.getById(id));
    }

    @GetMapping("/baseTrademark/getTrademarkList")
    public Result<List<BaseTrademark>> getTrademarkList() {
        return Result.ok(baseTrademarkService.list(null));
    }

}
